package com.cedric.yixianpai.server.controller;

import com.cedric.yixianpai.server.Utils.BestResult;
import com.cedric.yixianpai.server.Utils.CardInfoDTO;
import com.cedric.yixianpai.server.Utils.GameInfoDTO;
import com.cedric.yixianpai.server.Utils.GameResult;
import com.cedric.yixianpai.server.service.CardGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class CardGameController {
    @Autowired
    private CardGameService cardGameService;

    @PostMapping("/startGame")
    @ResponseBody
    public ResponseEntity<GameResult> startGame(@RequestBody GameInfoDTO gameInfoDTO) {
        GameResult result = cardGameService.startGame(gameInfoDTO);
        return ResponseEntity.ok(result);
    }

    @PostMapping("/findBest")
    @ResponseBody
    public ResponseEntity<BestResult> findBest(@RequestBody GameInfoDTO gameInfoDTO) {
//        System.out.println(gameInfoDTO);
        BestResult result = cardGameService.findBest(gameInfoDTO);
        return ResponseEntity.ok(result);
    }

    @GetMapping("/getCards")
    public ResponseEntity<List<CardInfoDTO>> getCards() {
        List<CardInfoDTO> result = cardGameService.getCards();
        return ResponseEntity.ok(result);
    }

}
